<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">
		<meta http-equiv="pragma" content="no-cache">
		<script type="text/javascript" src="js/tools/jquery-1.4.2.min.js"></script>
		<script type="text/javascript" src="js/tools/easyui/jquery.easyui.min.js"></script>
		<script type="text/javascript" src="js/tools/uploadFile.js"></script>
<script charset="utf-8" src="js/tools/editor/kindeditor-min.js"></script>
<script type="text/javascript" src="js/tools/jqueryurl.js"></script>
<script charset="utf-8" src="admin/js/public.js"></script>
<style>
table {font-size: 12px;}
table tr {background-color: #F1F6F6;}
table tr td {border: 1px solid #D9D9D9;color: black;padding: 2px;}
</style>
<script type="text/javascript">
var user='<s:property value="#session.user"/>';
KE.show({
				id : 'introduction',
				resizeMode : 1,
				imageUploadJson : 'image!uploadImageForEditor.action',
				directory:"uploadfile/business",
				width:800,
				height:400
			});
$(function(){
	
	$("input[type='checkbox']").click(function(){
	  if( $(this).attr("checked"))
	  {
	    $("#cont").hide();
	  }else
	  {
	    $("#cont").show();
	  }
	});
	var isNav='<s:property value="websiteColumn.isNav"/>';
	if(isNav==1)
	{
	  $("input[type='checkbox']").attr("checked",true);
	  $("#cont").hide();
	}
	var columnId=$.query.get("columnId");
	$("#columnId").val(columnId);
	categoryList("categoryId",columnId,-1,function(){
	   var isMofidy='<s:property value="business"/>';
	   if(isMofidy!='')
	   {
	       var categoryId='<s:property value="business.categoryId"/>';
	       var subCategoryId='<s:property value="business.subCategoryId"/>';
	      $("#categoryId").val(categoryId);
		      categoryList("subCategoryId",columnId,categoryId,function(){
		         $("#subCategoryId").val(subCategoryId);
		      });
	      $("#cardType").val('<s:property value="business.cardType"/>');
	      var recommend='<s:property value="business.recommend"/>'
	      if(recommend=="1")
	      {
	         $("#recommend").attr("checked",true);
	      }else
	      {
	         $("#recommend").attr("checked",false);
	      }
	      
	   }
	});
});
function check()
{

   $("#name,#categoryId").css("border","");
   var name=$.trim($("#name").val());
   var categoryId=$("#categoryId").val();
   var subCategoryId=$("#subCategoryId").val();
   var introduction=$.trim($("#introduction").val());
   var image=$("#image").val();
   if(name.length<1||name.length>50)
   {
     $("#name").css({"border": "2px solid red"});
      alert("名称的长度为1~50");
      return false;
   }
   if(categoryId==-2)
   {
      alert("必需选择根类别!");
      $("#categoryId").css({"border": "2px solid red"});
      return false;
   }
   if(image=="")
   {
     alert("请上传图片!");
     return false;
   }
   
  return true;
};
//上传图片
function uploadImage()
{
	var file=$("#file").val();
	if(file=="")
	{
		alert("选择图片");
		return false;
	}
          $.upload("image!uploadImage.action", {
              "directory": "uploadfile/business",
			  "base":  $("#base").val(),
              "image": $("#file")
          }, function (data) {
             if(data.info!="error")
             {
			 	$("#image").val(data.info);
			 	$("#apDiv").remove();
			 	var html="<div id='apDiv' style='position:absolute;width:158px;height:102px;z-index:1;left: 370px;top: 170px;'><img id='img' style='width:150px;height:100px;' src='"+data.info+"'></div>";
			 	$("body").append(html);
				alert("上传成功");
             }
          });
 }
</script>
	</head>
	<body>
	<input  type="hidden" id="base" value="<%=basePath%>">
	<s:actionmessage/>
	<s:if test="%{business == null}">
	    <form action="business!addBusiness.action" method="post" onsubmit="return check();">
	</s:if>
	<s:else>
	     <form action="business!modifyBusiness.action" method="post" onsubmit="return check();">
	     <input type="hidden" name="business.id" value="<s:property value="business.id"/>">
	</s:else>
	 <input type="hidden" name="columnId" id="columnId" value="">
	 <input type="hidden" name="business.image" id="image" value="<s:property value="business.image"/>">
		<table  style="width: 98%;" align="center">
			<tr><td width="10%">商家名称:</td><td><input type="text" name="business.name" id="name" value="<s:property value="business.name"/>" maxlength="50"/><font color=red>*必填</font></td></tr>
			<tr><td width="10%">商家总名称:</td><td><input type="text" name="business.pname" id="pname" value="<s:property value="business.pname"/>" maxlength="50"/></td></tr>
			<tr><td>类别:</td><td><select id="categoryId" name="business.categoryId" onchange="categoryList('subCategoryId',$.query.get('columnId'),$(this).val());"></select>&nbsp;&nbsp;子类别：<select name="business.subCategoryId" id="subCategoryId"><option value='-2'>选择类别</option></select></td></tr>
			<tr><td>电话:</td><td><input type="text" name="business.tel" id="tel" value="<s:property value="business.tel"/>"  maxlength="12"/></td></tr>
			<tr><td>网址:</td><td><input type="text" name="business.website" id="website" value="<s:property value="business.website"/>"  maxlength="100"/></td></tr>
			<tr><td>地址:</td><td><input type="text" name="business.address" id="address" value="<s:property value="business.address"/>"  maxlength="100"/></td></tr>
			<tr><td>推荐:</td><td><input type="checkbox" name="business.recommend" id="recommend" value="1"/></td></tr>
			<tr><td>金卡折扣:</td><td><input type="text" name="business.goldDiscount" id="goldDiscount" value="<s:property value="business.goldDiscount"/>"  maxlength="30"/></td></tr>
			<tr><td>VIP折扣:</td><td><input type="text" name="business.vipDiscount" id="vipDiscount" value="<s:property value="business.vipDiscount"/>"  maxlength="30"/></td></tr>
			<tr><td>图片:</td><td><input type="file" name="file" id="file" /><a href="javascript:void(0);" onclick="uploadImage()">上传</a></td></tr>
			<tr><td>商家介绍:</td><td><div><textarea name="business.introduction" id="introduction" rows="" cols=""><s:property value="business.introduction"/></textarea></div></td></tr>
			<tr><td><input type="submit"  value="保存"/></td><td><input type="button" onclick="window.location.href='admin/business/businessmanager.jsp?columnId='+$.query.get('columnId')" value="返回列表"/></td></tr>
		</table>
	</form>
	</body>
</html>
